<template>
  <van-action-sheet
    v-model="show"
    :title="title"
    :close-on-click-overlay="false"
    :close-on-popstate="closeOnPopstate"
    :lock-scroll="lockScroll"
    @cancel="handleCancel"
    @close="handleClose"
  >
    <!-- 自定义内容区域 -->
    <slot name="content"></slot>
    <!-- 底部按钮区域 -->
    <div v-if="showFooter">
      <div class="footer-buttons">
        <div type="default" @click="handleCancel" class="cancel-btn">
          {{ cancelText }}
        </div>
        <div type="info" @click="handleConfirm" class="confirm-btn">
          {{ confirmText }}
        </div>
      </div>
    </div>
  </van-action-sheet>
</template>
<script>
export default {
  name: 'CustomActionSheet',
  props: {
    modelValue: {
      type: Boolean,
      default: false,
    },
    title: {
      type: String,
      default: '',
    },
    confirmText: {
      type: String,
      default: function () {
        return this.$t('确认')
      },
    },
    cancelText: {
      type: String,
      default: function () {
        return this.$t('取消')
      },
    },
    showConfirmButton: {
      type: Boolean,
      default: true,
    },
    showCancelButton: {
      type: Boolean,
      default: true,
    },
    showFooter: {
      type: Boolean,
      default: true,
    },
    closeOnClickOverlay: {
      type: Boolean,
      default: true,
    },
    closeOnPopstate: {
      type: Boolean,
      default: true,
    },
    lockScroll: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      show: this.modelValue,
    }
  },
  watch: {
    modelValue(newVal) {
      this.show = newVal
    },
    show(newVal) {
      this.$emit('update:modelValue', newVal)
    },
  },
  methods: {
    handleCancel() {
      this.$emit('cancel')
      // this.show = false;
    },
    handleConfirm() {
      this.$emit('confirm')
    },
    handleClose() {
      this.$emit('close')
      this.show = false
    },
  },
}
</script>
<style scoped>
.footer-buttons {
  background: #fff;
  position: fixed;
  display: flex;
  gap: 10px;
  padding: 16px;
  bottom: 0;
  left: 0;
  right: 0;
  box-sizing: border-box;
  z-index: 100;
}

.cancel-btn {
  flex: 1;
  width: 50%;
  display: flex;

  justify-content: center;
  align-items: center;
  height: 44px;
  border-radius: 22px;
  border: 1px solid #999999;
  font-size: 14px;
}

.confirm-btn {
  flex: 1;
  display: flex;
  width: 50%;
  height: 44px;
  color: #fff;
  justify-content: center;
  align-items: center;
  background: linear-gradient(90deg, #7683f6 0%, #2f31f1 100%);
  border-radius: 22px;
  font-size: 14px;
}
</style>
